package com.efast.dmom.mgmt.service.les.impl;

import com.efast.cafe.framework.exception.ServiceException;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mgmt.bean.les.LocDlocWhBean;
import com.efast.dmom.mgmt.bean.les.TwInvSkuLoctlBean;
import com.efast.dmom.mgmt.bean.les.TwInvSkuLoctlStatementBean;
import com.efast.dmom.mgmt.dao.les.*;
import com.efast.dmom.mgmt.entity.les.*;
import com.efast.dmom.mgmt.service.les.TwInvSkuLoctlService;
import com.efast.dmom.mgmt.utils.Assist;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author ChenLiPeng
 * @date 2018年4月17日
 */
@Service
public class TwInvSkuLoctlServiceImpl implements TwInvSkuLoctlService {

	/**
	 * 库存表---tw_inv_sku_loc_t_l
	 */
	private final TwInvSkuLoctlDao twInvSkuLoctlDao;

	/**
	 * 库存交易表--TW_ACT_TRAN_LOG
	 */
	private final TwActTranLogDao twActTranLogDao;

	/**
	 * 零件批次属性组头配置 tw_bas_part_batch_header
	 */
	private final TwBasPartBatchHeaderDao twBasPartBatchHeaderDao;

	/**
	 * 零件批次属性表 tw_bas_part_batch
	 */
	private final TwBasPartBatchDao twBasPartBatchDao;

	/**
	 * 零件仓储关系
	 */
	private final TrBasPartStorageDao trBasPartStorageDao;

	@Autowired
	public TwInvSkuLoctlServiceImpl(TwInvSkuLoctlDao twInvSkuLoctlDao, TwActTranLogDao twActTranLogDao,
			TwBasPartBatchHeaderDao twBasPartBatchHeaderDao, TwBasPartBatchDao twBasPartBatchDao,
			TrBasPartStorageDao trBasPartStorageDao) {
		this.twInvSkuLoctlDao = twInvSkuLoctlDao;
		this.twActTranLogDao = twActTranLogDao;
		this.twBasPartBatchHeaderDao = twBasPartBatchHeaderDao;
		this.twBasPartBatchDao = twBasPartBatchDao;
		this.trBasPartStorageDao = trBasPartStorageDao;
	}

	/**
	 * 通过库位id ， 查询库区和仓库
	 */
	@Override
	public LocDlocWhBean queryParentNo(int tmBasStorageId) {
		return twInvSkuLoctlDao.queryParentNo(tmBasStorageId);
	}

	/**
	 * 库存调整
	 */
	@Override
	public int updateNonEmptyTwInvSkuLoctlById(TwInvSkuLoctlBean twInvSkuLoctlBean) {

		TwInvSkuLoctl twInvSkuLoctl = twInvSkuLoctlBean.getTwInvSkuLoctl();
		TwActTranLog twActTranLog = twInvSkuLoctlBean.getTwActTranLog();

		// 【1】：通过库位id，找到库区，仓库。
		LocDlocWhBean locDlocWhBean = twInvSkuLoctlDao.queryParentNo(twInvSkuLoctl.getTmBasStorageId());

		// 【2】：通过id，查询tw_inv_sku_loc_t_l的原始数据
		TwInvSkuLoctl dbTwInvSkuLoctl = twInvSkuLoctlDao.selectTwInvSkuLoctlById(twInvSkuLoctl.getTwInvSkuLoctlId());

		// 【3】：插入 库存交易表TW_ACT_TRAN_LOG
		// 操作人
		twActTranLog.setOperator(SpringWebUtils.getRequestUser());
		// 交易时间
		twActTranLog.setTransTime(new Date());
		// 是否允许上传SAP0不允许1允许
		twActTranLog.setIsCanTosap("1");
		// 1为已生成接口数据
		twActTranLog.setFlag(0);
		// 是否已上传SAP
		twActTranLog.setIsTosap("0");
		// 交易类型 （入库0、分配1、拣货2、出库3、移动4、调整5）
		twActTranLog.setTransType("5");
		// twActTranLog.setCostCenter();//成本中心
		// twActTranLog.setDocLineno();//交易涉及单证行号
		// twActTranLog.setTransCode();//移动代码
		// twActTranLog.setDStorageNo();//SAP目的存储地点

		// twActTranLog.setFmCustomerid();//From 客户
		// twActTranLog.setTransReasonCode();//移动原因代码
		// twActTranLog.setFmPackid();//原始包装
		// twActTranLog.setInnerOrder();//内部订单
		// 原始库位交易数量
		twActTranLog.setFmQty(dbTwInvSkuLoctl.getCurQty());
		// 原始仓库
		twActTranLog.setFmWarehouse(locDlocWhBean.getWarehomeNo());
		// 原始库区
		twActTranLog.setFmArea(locDlocWhBean.getDlocNo());
		// 原始库位
		twActTranLog.setFmLocation(locDlocWhBean.getLocNo());
		// From 产品
		twActTranLog.setFmPartNo(twInvSkuLoctl.getPartNoVersion());
		// From 供应商号
		twActTranLog.setFmSupplierNo(twInvSkuLoctl.getSupplNo());
		// 基本单位
		twActTranLog.setBaseUnit(twInvSkuLoctl.getBaseUnit());
		// 原始库位单位
		twActTranLog.setFmUom(twInvSkuLoctl.getBaseUnit());
		// 原始跟踪号
		twActTranLog.setFmId(twInvSkuLoctl.getInbSerialNo());
		// 原始批次号
		twActTranLog.setFmLotnum(twInvSkuLoctl.getLotNo());

		// twActTranLog.setToPackid();//目标包装ID
		// twActTranLog.setToCustomerid();//To 客户
		// 目标库位交易数量
		twActTranLog.setToQty(twInvSkuLoctl.getCurQty());
		// 目标仓库
		twActTranLog.setToWarehouse(locDlocWhBean.getWarehomeNo());
		// 目标库区
		twActTranLog.setToArea(locDlocWhBean.getDlocNo());
		// 目标库位
		twActTranLog.setToLocation(locDlocWhBean.getLocNo());
		// 目标跟踪号
		twActTranLog.setToId(twInvSkuLoctl.getPartPackSerial());
		// To 供应商号
		twActTranLog.setToSupplierNo(twInvSkuLoctl.getSupplNo());
		// 目标批次号
		twActTranLog.setToLotnum(twInvSkuLoctl.getLotNo());
		// 目标单位
		twActTranLog.setToUom(twInvSkuLoctl.getBaseUnit());
		// To 产品
		twActTranLog.setToPartNo(twInvSkuLoctl.getPartNoVersion());

		// twActTranLog.setDocType();//库存交易涉及单据类型（到货通知单0、上架作业单1、拣货作业单2、补货作业单3、翻包作业单4、装箱作业单5、装车发运单6、出库订单7、库存调整单8、库存移动单9）
		// twActTranLog.setDocno();//交易涉及单据号
		// twActTranLog.setReasonCode();//原因代码
		// twActTranLog.setInterfaceGroupId();//接口汇总组号
		// twActTranLog.setSapTransType();//移动类型
		// twActTranLog.setAcount();//凭证抬头文本
		// twActTranLog.setSStorageNo();//SAP源存储地点
		// twActTranLog.setEcrno();//ECR编号
		// twActTranLog.setReasonDesc();//原因
		// twActTranLog.setNotes();//备注
		// twActTranLog.setNote1();//备注1(工厂)
		// twActTranLog.setNote2();//备注2（车间）
		// twActTranLog.setNote3();//备注3
		// twActTranLog.setNote4();//备注4
		// twActTranLog.setNote5();//备注5
		// twActTranLog.setNote6();//备注6
		// twActTranLog.setNote7();//备注7
		// twActTranLog.setNote8();//备注8
		// twActTranLog.setNote9();//备注9
		// 版本控制
		twActTranLog.setOptCounter(1);
		// 是否激活
		twActTranLog.setMarkStatus(1);
		// 创建时间
		twActTranLog.setCreateTime(new Date());
		// 创建用户
		twActTranLog.setCreateUser(SpringWebUtils.getRequestUser());
		// 企业代码
		twActTranLog.setCompanyCode(SpringWebUtils.getRequestCompany());
		twActTranLogDao.insertNonEmptyTwActTranLog(twActTranLog);

		// 【4】：更新库存表
		TwInvSkuLoctl twInvSkuLoctl2 = new TwInvSkuLoctl();
		twInvSkuLoctl2.setTwInvSkuLoctlId(twInvSkuLoctl.getTwInvSkuLoctlId());
		if (twInvSkuLoctl.getAvailableQty() != null) {
			if (dbTwInvSkuLoctl.getAvailableQty() + twInvSkuLoctl.getAvailableQty() < 0) {
				throw new ServiceException("可用数量调整不能小于0");
			}
			// 可用数量
			twInvSkuLoctl2.setAvailableQty(dbTwInvSkuLoctl.getAvailableQty() + twInvSkuLoctl.getAvailableQty());
			// 库存数量
			twInvSkuLoctl2.setCurQty(dbTwInvSkuLoctl.getCurQty() + twInvSkuLoctl.getAvailableQty());
		}

		if (twInvSkuLoctl.getHoldQty() != null) {
			if (dbTwInvSkuLoctl.getHoldQty() + twInvSkuLoctl.getHoldQty() < 0) {
				throw new ServiceException("冻结数量调整不能小于0");
			}
			// 冻结数量
			twInvSkuLoctl2.setHoldQty(dbTwInvSkuLoctl.getHoldQty() + twInvSkuLoctl.getHoldQty());
		}

		if (twInvSkuLoctl.getTrarInbQty() != null) {
			if (dbTwInvSkuLoctl.getTrarInbQty() + twInvSkuLoctl.getTrarInbQty() < 0) {
				throw new ServiceException("待转移移入数量不能小于0");
			}
			// 待转移移入数量
			twInvSkuLoctl2.setTrarInbQty(dbTwInvSkuLoctl.getTrarInbQty() + twInvSkuLoctl.getTrarInbQty());
		}

		if (twInvSkuLoctl.getPackageNum() != null) {
			if (dbTwInvSkuLoctl.getPackageNum() + twInvSkuLoctl.getPackageNum() < 0) {
				throw new ServiceException("箱数不能小于0");
			}
			// 箱数
			twInvSkuLoctl2.setPackageNum(dbTwInvSkuLoctl.getPackageNum() + twInvSkuLoctl.getPackageNum());
		}

		if (twInvSkuLoctl.getRebrInbQty() != null) {
			if (dbTwInvSkuLoctl.getRebrInbQty() + twInvSkuLoctl.getRebrInbQty() < 0) {
				throw new ServiceException("待补货移入数量不能小于0");
			}
			// 待补货移入数量
			twInvSkuLoctl2.setRebrInbQty(dbTwInvSkuLoctl.getRebrInbQty() + twInvSkuLoctl.getRebrInbQty());
		}

		if (twInvSkuLoctl.getCprInbQty() != null) {
			if (dbTwInvSkuLoctl.getCprInbQty() + twInvSkuLoctl.getCprInbQty() < 0) {
				throw new ServiceException("待翻包完移入数量不能小于0");
			}
			// 待翻包完移入数量
			twInvSkuLoctl2.setCprInbQty(dbTwInvSkuLoctl.getCprInbQty() + twInvSkuLoctl.getCprInbQty());
		}

		if (twInvSkuLoctl.getSorAllocQty() != null) {
			if (dbTwInvSkuLoctl.getSorAllocQty() + twInvSkuLoctl.getSorAllocQty() < 0) {
				throw new ServiceException("出库订单分配数量不能小于0");
			}
			// 出库订单分配数量
			twInvSkuLoctl2.setSorAllocQty(dbTwInvSkuLoctl.getSorAllocQty() + twInvSkuLoctl.getSorAllocQty());
		}

		if (twInvSkuLoctl.getRebrAllocQty() != null) {
			if (dbTwInvSkuLoctl.getRebrAllocQty() + twInvSkuLoctl.getRebrAllocQty() < 0) {
				throw new ServiceException("补货分配数量不能小于0");
			}
			// 补货分配数量
			twInvSkuLoctl2.setRebrAllocQty(dbTwInvSkuLoctl.getRebrAllocQty() + twInvSkuLoctl.getRebrAllocQty());
		}
		twInvSkuLoctl2.setLotatt01(twInvSkuLoctl.getLotatt01());
		twInvSkuLoctl2.setLotatt02(twInvSkuLoctl.getLotatt02());
		twInvSkuLoctl2.setLotatt03(twInvSkuLoctl.getLotatt03());
		twInvSkuLoctl2.setLotatt04(twInvSkuLoctl.getLotatt04());
		twInvSkuLoctl2.setLotatt05(twInvSkuLoctl.getLotatt05());
		twInvSkuLoctl2.setLotatt06(twInvSkuLoctl.getLotatt06());
		return twInvSkuLoctlDao.updateNonEmptyTwInvSkuLoctlById(twInvSkuLoctl2);
	}

	/**
	 * 库存移动
	 * 
	 * @param twInvSkuLoctlBean
	 *            twInvSkuLoctlBean
	 */
	@Override
	public void inventoryMovement(TwInvSkuLoctlBean twInvSkuLoctlBean) {

		TwInvSkuLoctl twInvSkuLoctl = twInvSkuLoctlBean.getTwInvSkuLoctl();
		TwInvSkuLoctl dbTwInvSkuLoctl1 = twInvSkuLoctlDao.selectTwInvSkuLoctlById(twInvSkuLoctl.getTwInvSkuLoctlId());
		// 可以更改供应商，前提是零件-目标供应商 维护了对应的批次属性
		if (StringUtils.isNotBlank(twInvSkuLoctl.getLotatt04())) {
			if (!twInvSkuLoctl.getLotatt04().equals(dbTwInvSkuLoctl1.getLotatt04())) {
				List<TwBasPartBatchHeader> twBasPartBatchHeaders = twBasPartBatchHeaderDao.selectTwBasPartBatchHeader(
						new Assist(Assist.andEq("part_no_version", twInvSkuLoctl.getPartNoVersion()),
								Assist.andEq("suppl_no", twInvSkuLoctl.getSupplNo())));
				if (twBasPartBatchHeaders.size() == 0) {
					throw new ServiceException(twInvSkuLoctl.getPartNoVersion() + "零件-目标供应商 没有维护了对应的批次属性");
				}
				List<TwBasPartBatch> listTwBasPartBatch = twBasPartBatchDao.selectTwBasPartBatch(
						new Assist(Assist.andEq("tw_bas_part_batch_header_id",
								twBasPartBatchHeaders.get(0).getTwBasPartBatchHeaderId())));
				if (listTwBasPartBatch.size() == 0) {
					throw new ServiceException(twInvSkuLoctl.getPartNoVersion() + "零件-目标供应商 没有维护了对应的批次属性");
				}
			}
		}

		// 未填写目标包装号的情况下：
		// 可以手动修改包装，按照如下顺序依次查找手动修改的包装数据，包括是否存在当前包装和包装容量
		// 1.据根据目标供应商、零件号、目标库位/库区/仓库、配送单位查找包装代码和包装容量
		// 2.默认包装为“SJZ001”，包装容量默认为999999
		if (StringUtils.isBlank(twInvSkuLoctl.getPartPackSerial())) {
			List<TrBasPartStorage> trBasPartStorages = trBasPartStorageDao.selectTrBasPartStorage(
					new Assist(Assist.andEq("part_no_version", twInvSkuLoctl.getPartNoVersion()),
							Assist.andEq("suppl_no", dbTwInvSkuLoctl1.getSupplNo()),
							Assist.andEq("part_no_version", twInvSkuLoctl.getTmBasStorageId()),
							Assist.andEq("loc_id", twInvSkuLoctl.getTmBasStorageId())));
			if (trBasPartStorages.size() != 0) {
				twInvSkuLoctl = setInboundPack(twInvSkuLoctl, trBasPartStorages.get(0));
			} else {
				twInvSkuLoctl.setInboundPackNo("SJZ001");
				twInvSkuLoctl.setInboundPackQty(999999);
			}
		} else {
			// 填写了目标包装号的情况下
			// 可以手动修改包装，按照如下顺序依次查找手动修改的包装数据，包括是否存在当前包装和包装容量
			// 1.根据目标供应商、零件号、源库位、目标包装号、配送单位查找包装代码和包装容量
			// 2.据据目标供应商、零件号、目标库位/库区/仓库、配送单位查找包装代码和包装容量
			// 3.按照手动填写的包装号更新、包装容量沿用源包装容量
			List<TrBasPartStorage> trBasPartStorages = trBasPartStorageDao.selectTrBasPartStorage(
					new Assist(Assist.andEq("part_no_version", twInvSkuLoctl.getPartNoVersion()),
							Assist.andEq("suppl_no", twInvSkuLoctl.getLotatt04()),
							Assist.andEq("part_no_version", twInvSkuLoctl.getPartNoVersion()),
							Assist.andEq("loc_id", dbTwInvSkuLoctl1.getTmBasStorageId())));
//							Assist.andEq("part_pack_serial", twInvSkuLoctl.getPartPackSerial())));
			if (trBasPartStorages.size() != 0) {
				twInvSkuLoctl = setInboundPack(twInvSkuLoctl, trBasPartStorages.get(0));
			} else {
				List<TrBasPartStorage> trBasPartStorages1 = trBasPartStorageDao.selectTrBasPartStorage(
						new Assist(Assist.andEq("part_no_version", twInvSkuLoctl.getPartNoVersion()),
								Assist.andEq("suppl_no", twInvSkuLoctl.getLotatt04()),
								Assist.andEq("part_no_version", twInvSkuLoctl.getPartNoVersion()),
								Assist.andEq("loc_id", twInvSkuLoctl.getTmBasStorageId())));
				if (trBasPartStorages1.size() != 0) {
					twInvSkuLoctl = setInboundPack(twInvSkuLoctl, trBasPartStorages.get(0));
				} else {
					twInvSkuLoctl.setInboundPackQty(dbTwInvSkuLoctl1.getInboundPackQty());
				}
			}
		}
		// 更新源库位的库存
		TwInvSkuLoctl twInvSkuLoctl3 = twInvSkuLoctlDao.selectTwInvSkuLoctlById(twInvSkuLoctl.getTwInvSkuLoctlId());
		TwInvSkuLoctl twInvSkuLoctl2 = new TwInvSkuLoctl();
		twInvSkuLoctl2.setTwInvSkuLoctlId(twInvSkuLoctl.getTwInvSkuLoctlId());
		twInvSkuLoctl2.setCurQty(twInvSkuLoctl3.getCurQty() - twInvSkuLoctl.getCurQty());
		twInvSkuLoctl2.setAvailableQty(twInvSkuLoctl3.getAvailableQty() - twInvSkuLoctl.getCurQty());
		twInvSkuLoctlDao.updateNonEmptyTwInvSkuLoctlById(twInvSkuLoctl2);

		// 更新目标库位的库存
		// 如果 零件+供应商+库位+入库跟踪号+零件包装流水号+批次 那么update，否则是新增
		if (twInvSkuLoctl.getLocNo() != null && twInvSkuLoctl.getLocNo() != null
				&& twInvSkuLoctl.getPartPackSerial() != null && twInvSkuLoctl.getInbSerialNo() != null) {
			Assist assist = new Assist();
			assist.setRequires(Assist.andEq("part_no_version", twInvSkuLoctl.getPartNoVersion()));
			assist.setRequires(Assist.andEq("suppl_no", twInvSkuLoctl.getSupplNo()));
			assist.setRequires(Assist.andEq("loc_no", twInvSkuLoctl.getLocNo()));
			assist.setRequires(Assist.andEq("lot_no", twInvSkuLoctl.getLotNo()));
			assist.setRequires(Assist.andEq("part_pack_serial", twInvSkuLoctl.getPartPackSerial()));
			assist.setRequires(Assist.andEq("inb_serial_no", twInvSkuLoctl.getInbSerialNo()));
			List<TwInvSkuLoctl> twInvSkuLoctls = twInvSkuLoctlDao.selectTwInvSkuLoctl(assist);
			// 新增
			if (twInvSkuLoctls.size() == 0) {
				twInvSkuLoctl.setTwInvSkuLoctlId(null);
				twInvSkuLoctl.setMarkStatus(1);
				twInvSkuLoctl.setCreateUser(SpringWebUtils.getRequestUser());
				twInvSkuLoctl.setCompanyCode(SpringWebUtils.getRequestCompany());
				twInvSkuLoctl.setCreateTime(new Date());
				twInvSkuLoctlDao.insertNonEmptyTwInvSkuLoctl(twInvSkuLoctl);
			} else {
				TwInvSkuLoctl twInvSkuLoctl1 = new TwInvSkuLoctl();
				twInvSkuLoctl1.setTwInvSkuLoctlId(twInvSkuLoctls.get(0).getTwInvSkuLoctlId());
				twInvSkuLoctl1.setCurQty(twInvSkuLoctls.get(0).getCurQty() + twInvSkuLoctl.getCurQty());
				twInvSkuLoctl1.setAvailableQty(twInvSkuLoctls.get(0).getAvailableQty() + twInvSkuLoctl.getCurQty());
				twInvSkuLoctlDao.updateNonEmptyTwInvSkuLoctlById(twInvSkuLoctl1);
			}
		} else {
            TwInvSkuLoctl twInvSkuLoctl1 = new TwInvSkuLoctl();
            BeanUtils.copyProperties(dbTwInvSkuLoctl1,twInvSkuLoctl1);
            twInvSkuLoctl1.setCurQty(twInvSkuLoctl.getCurQty());
            twInvSkuLoctl1.setAvailableQty(twInvSkuLoctl.getCurQty());
            twInvSkuLoctl1.setWarehouseNo(twInvSkuLoctl.getWarehouseNo());
            twInvSkuLoctl1.setDlocNo(twInvSkuLoctl.getDlocNo());
            twInvSkuLoctl1.setLocNo(twInvSkuLoctl.getLocNo());
            twInvSkuLoctl1.setTwInvSkuLoctlId(null);
			twInvSkuLoctl1.setMarkStatus(1);
			twInvSkuLoctl1.setCreateUser(SpringWebUtils.getRequestUser());
			twInvSkuLoctl1.setCompanyCode(SpringWebUtils.getRequestCompany());
			twInvSkuLoctl1.setCreateTime(new Date());
			twInvSkuLoctlDao.insertNonEmptyTwInvSkuLoctl(twInvSkuLoctl1);
		}

		// 插入 库存交易表TW_ACT_TRAN_LOG
		// 通过库位id，找到库区，仓库。
		LocDlocWhBean locDlocWhBean = twInvSkuLoctlDao.queryParentNo(twInvSkuLoctl.getTmBasStorageId());
		TwActTranLog twActTranLog = twInvSkuLoctlBean.getTwActTranLog();
		// 操作人
		twActTranLog.setOperator(SpringWebUtils.getRequestUser());
		// 交易时间
		twActTranLog.setTransTime(new Date());
		// 是否允许上传SAP0不允许1允许
		twActTranLog.setIsCanTosap("1");
		// 1为已生成接口数据
		twActTranLog.setFlag(0);
		// 是否已上传SAP
		twActTranLog.setIsTosap("0");
		// 交易类型 （入库0、分配1、拣货2、出库3、移动4、调整5）
		twActTranLog.setTransType("5");
		// twActTranLog.setCostCenter();//成本中心
		// twActTranLog.setDocLineno();//交易涉及单证行号
		// twActTranLog.setTransCode();//移动代码
		// twActTranLog.setDStorageNo();//SAP目的存储地点

		// twActTranLog.setFmCustomerid();//From 客户
		// twActTranLog.setTransReasonCode();//移动原因代码
		// twActTranLog.setFmPackid();//原始包装
		// twActTranLog.setInnerOrder();//内部订单
		// 原始库位交易数量
		twActTranLog.setFmQty(twInvSkuLoctl.getCurQty());
		// 原始仓库
		twActTranLog.setFmWarehouse(locDlocWhBean.getWarehomeNo());
		// 原始库区
		twActTranLog.setFmArea(locDlocWhBean.getDlocNo());
		// 原始库位
		twActTranLog.setFmLocation(locDlocWhBean.getLocNo());
		// From 产品
		twActTranLog.setFmPartNo(twInvSkuLoctl.getPartNoVersion());
		// From 供应商号
		twActTranLog.setFmSupplierNo(twInvSkuLoctl.getSupplNo());
		// 基本单位
		twActTranLog.setBaseUnit(twInvSkuLoctl.getBaseUnit());
		// 原始库位单位
		twActTranLog.setFmUom(twInvSkuLoctl.getBaseUnit());
		// 原始跟踪号
		twActTranLog.setFmId(twInvSkuLoctl.getInbSerialNo());
		// 原始批次号
		twActTranLog.setFmLotnum(twInvSkuLoctl.getLotNo());

		// twActTranLog.setToPackid();//目标包装ID
		// twActTranLog.setToCustomerid();//To 客户
		// 目标库位交易数量
		twActTranLog.setToQty(twInvSkuLoctl.getCurQty());
		// 目标仓库
		twActTranLog.setToWarehouse(locDlocWhBean.getWarehomeNo());
		// 目标库区
		twActTranLog.setToArea(locDlocWhBean.getDlocNo());
		// 目标库位
		twActTranLog.setToLocation(locDlocWhBean.getLocNo());
		// 目标跟踪号
		twActTranLog.setToId(twInvSkuLoctl.getPartPackSerial());
		// To 供应商号
		twActTranLog.setToSupplierNo(twInvSkuLoctl.getSupplNo());
		// 目标批次号
		twActTranLog.setToLotnum(twInvSkuLoctl.getLotNo());
		// 目标单位
		twActTranLog.setToUom(twInvSkuLoctl.getBaseUnit());
		// To 产品
		twActTranLog.setToPartNo(twInvSkuLoctl.getPartNoVersion());

		// twActTranLog.setDocType();//库存交易涉及单据类型（到货通知单0、上架作业单1、拣货作业单2、补货作业单3、翻包作业单4、装箱作业单5、装车发运单6、出库订单7、库存调整单8、库存移动单9）
		// twActTranLog.setDocno();//交易涉及单据号
		// twActTranLog.setReasonCode();//原因代码
		// twActTranLog.setInterfaceGroupId();//接口汇总组号
		// twActTranLog.setSapTransType();//移动类型
		// twActTranLog.setAcount();//凭证抬头文本
		// twActTranLog.setSStorageNo();//SAP源存储地点
		// twActTranLog.setEcrno();//ECR编号
		// twActTranLog.setReasonDesc();//原因
		// twActTranLog.setNotes();//备注
		// twActTranLog.setNote1();//备注1(工厂)
		// twActTranLog.setNote2();//备注2（车间）
		// twActTranLog.setNote3();//备注3
		// twActTranLog.setNote4();//备注4
		// twActTranLog.setNote5();//备注5
		// twActTranLog.setNote6();//备注6
		// twActTranLog.setNote7();//备注7
		// twActTranLog.setNote8();//备注8
		// twActTranLog.setNote9();//备注9
		// 版本控制
		twActTranLog.setOptCounter(1);
		// 是否激活
		twActTranLog.setMarkStatus(1);
		// 创建时间
		twActTranLog.setCreateTime(new Date());
		// 创建用户
		twActTranLog.setCreateUser(SpringWebUtils.getRequestUser());
		// 企业代码
		twActTranLog.setCompanyCode(SpringWebUtils.getRequestCompany());
		twActTranLogDao.insertNonEmptyTwActTranLog(twActTranLog);
	}

	private TwInvSkuLoctl setInboundPack(TwInvSkuLoctl twInvSkuLoctl, TrBasPartStorage trBasPartStorage) {
		// 入库包装代码
		twInvSkuLoctl.setInboundPackNo(trBasPartStorage.getPackageNo());
		// 入库包装容量
		double d = trBasPartStorage.getInboundPackQty();
		String s1 = String.valueOf(d);
		String s2 = s1.substring(0, s1.indexOf(".")) + s1.substring(s1.indexOf(".") + 1);
		int i = Integer.parseInt(s2);
		twInvSkuLoctl.setInboundPackQty(i);
		return twInvSkuLoctl;
	}

	/**
	 * 通过库位id，找到库区，仓库
	 */
	@Override
	public TwInvSkuLoctlStatementBean queryStatement() {
		return twInvSkuLoctlDao.queryStatement();
	}

	@Override
	public long getTwInvSkuLoctlRowCount(Assist assist) {
		return twInvSkuLoctlDao.getTwInvSkuLoctlRowCount(assist);
	}

	@Override
	public List<TwInvSkuLoctl> selectTwInvSkuLoctl(Assist assist) {
		return twInvSkuLoctlDao.selectTwInvSkuLoctl(assist);
	}

	@Override
	public TwInvSkuLoctl selectTwInvSkuLoctlByObj(TwInvSkuLoctl obj) {
		return twInvSkuLoctlDao.selectTwInvSkuLoctlByObj(obj);
	}

	@Override
	public TwInvSkuLoctl selectTwInvSkuLoctlById(Integer id) {
		return twInvSkuLoctlDao.selectTwInvSkuLoctlById(id);
	}

	@Override
	public int insertTwInvSkuLoctl(TwInvSkuLoctl value) {
		return twInvSkuLoctlDao.insertTwInvSkuLoctl(value);
	}

	@Override
	public int insertNonEmptyTwInvSkuLoctl(TwInvSkuLoctl value) {
		return twInvSkuLoctlDao.insertNonEmptyTwInvSkuLoctl(value);
	}

	@Override
	public int insertTwInvSkuLoctlByBatch(List<TwInvSkuLoctl> value) {
		return twInvSkuLoctlDao.insertTwInvSkuLoctlByBatch(value);
	}

	@Override
	public int deleteTwInvSkuLoctlById(Integer id) {
		return twInvSkuLoctlDao.deleteTwInvSkuLoctlById(id);
	}

	@Override
	public int deleteTwInvSkuLoctl(Assist assist) {
		return twInvSkuLoctlDao.deleteTwInvSkuLoctl(assist);
	}

	@Override
	public int updateTwInvSkuLoctlById(TwInvSkuLoctl enti) {
		return twInvSkuLoctlDao.updateTwInvSkuLoctlById(enti);
	}

	@Override
	public int updateTwInvSkuLoctl(TwInvSkuLoctl value, Assist assist) {
		return twInvSkuLoctlDao.updateTwInvSkuLoctl(value, assist);
	}

	@Override
	public int updateNonEmptyTwInvSkuLoctl(TwInvSkuLoctl value, Assist assist) {
		return twInvSkuLoctlDao.updateNonEmptyTwInvSkuLoctl(value, assist);
	}

}